﻿#ifndef C_C_DEF_H
#define C_C_DEF_H

#include "InfFile.h"

// 用户态模块 - 窄字符
#define TEXT_PREF

// Bus和Root共用一个HWID
#define C0C_BUS_DEVICE_ID           TEXT_PREF"root\\com0com"
#define C0C_PORT_DEVICE_ID          TEXT_PREF"com0com\\port"
#define C0C_PORT_HW_ID_CNCCLASS     TEXT_PREF"com0com\\cncport"
#define C0C_PORT_HW_ID_COMCLASS     TEXT_PREF"com0com\\comport"
#define C0C_SERVICE                 TEXT_PREF"com0com"
#define C0C_PREF_NT_DEVICE_NAME     TEXT_PREF"\\Device\\"

#define C0C_PORT_NAME_LEN           12
#define C0C_PREF_BUS_NAME           TEXT_PREF"CNCBUS"
#define C0C_PREF_PORT_NAME_A        TEXT_PREF"CNCA"
#define C0C_PREF_PORT_NAME_B        TEXT_PREF"CNCB"
#define C0C_PREF_DEVICE_NAME_A      C0C_PREF_NT_DEVICE_NAME C0C_SERVICE TEXT_PREF"1"
#define C0C_PREF_DEVICE_NAME_B      C0C_PREF_NT_DEVICE_NAME C0C_SERVICE TEXT_PREF"2"
#define C0C_PORT_NAME_COMCLASS      TEXT_PREF"COM#"

#define C0C_REGSTR_VAL_PORT_NUM     TEXT_PREF"PortNum"

#define C0C_PIN_RRTS                0x00000001
#define C0C_PIN_RDTR                0x00000002
#define C0C_PIN_ROUT1               0x00000004
#define C0C_PIN_ROUT2               0x00000008
#define C0C_PIN_ROPEN               0x00000080
#define C0C_PIN_LRTS                0x00000100
#define C0C_PIN_LDTR                0x00000200
#define C0C_PIN_LOUT1               0x00000400
#define C0C_PIN_LOUT2               0x00000800
#define C0C_PIN_LOPEN               0x00008000
#define C0C_PIN_ON                  0x10000000
#define C0C_PIN_NEGATIVE            0x80000000

#define C0C_DEFAULT_PIN_CTS         C0C_PIN_RRTS
#define C0C_DEFAULT_PIN_DSR         C0C_PIN_RDTR
#define C0C_DEFAULT_PIN_DCD         C0C_PIN_RDTR
#define C0C_DEFAULT_PIN_RI          (C0C_PIN_ON|C0C_PIN_NEGATIVE)

#define C0C_DEFAULT_EMUBR           0x00000000
#define C0C_DEFAULT_EMUOVERRUN      0x00000000
#define C0C_DEFAULT_PLUGINMODE      0x00000000
#define C0C_DEFAULT_EXCLUSIVEMODE   0x00000000
#define C0C_DEFAULT_HIDDENMODE      0x00000000
#define C0C_DEFAULT_ALLDATABITS     0x00000000
#define C0C_DEFAULT_EMUNOISE        0x00000000
#define C0C_DEFAULT_ADDRTTO         0x00000000
#define C0C_DEFAULT_ADDRITO         0x00000000

#define C0C_PROBABILITY_ONE         100000000

/////////////////// INSTALL PARAMS //////////////////////

#define C0C_SYS_DIR              "sys\\"
#define C0C_INF_NAME             "com0com.inf"
#define C0C_INF_NAME_CNCPORT     "cncport.inf"
#define C0C_INF_NAME_COMPORT     "comport.inf"
#define C0C_CNCCLASS_GUID        "{df799e12-3c56-421b-b298-b6d3642bc878}"
#define C0C_COMCLASS_GUID        "{4d36e978-e325-11ce-bfc1-08002be10318}"
#define C0C_PROVIDER             "Vyacheslav Frolov"
#define C0C_REGKEY_EVENTLOG      REGSTR_PATH_SERVICES "\\Eventlog\\System\\" C0C_SERVICE
#define C0C_COPY_DRIVERS_SECTION "com0com_CopyDrivers"

#define C0C_SETUP_TITLE          "Setup for com0com"

static const InfFile::InfFileField requiredFieldsInfBusInstall[] = {
    { "Version",         "ClassGUID",          1, C0C_CNCCLASS_GUID },
    { "Version",         "Provider",           1, C0C_PROVIDER },
    { "Version",         "UninstallInfTag",    1, C0C_CNCCLASS_GUID },
    { "Manufacturer",    NULL,                 1, C0C_SERVICE },
    { NULL },
    };

static const InfFile::InfFileField requiredFieldsInfCNCPortInstall[] = {
    { "Version",         "ClassGUID",          1, C0C_CNCCLASS_GUID },
    { "Version",         "Provider",           1, C0C_PROVIDER },
    { "Version",         "UninstallInfTag",    1, C0C_CNCCLASS_GUID },
    { "Manufacturer",    NULL,                 1, C0C_SERVICE },
    { NULL },
    };

static const InfFile::InfFileField requiredFieldsInfCOMPortInstall[] = {
    { "Version",         "ClassGUID",          1, C0C_COMCLASS_GUID },
    { "Version",         "Provider",           1, C0C_PROVIDER },
    { "Version",         "UninstallInfTag",    1, C0C_CNCCLASS_GUID },
    { "Manufacturer",    NULL,                 1, C0C_SERVICE },
    { NULL },
    };

struct InfFileInstall {
    const char *pInfName;
    const char *pCopyDriversSection;
    const char *pHardwareId;
    bool preinstallClass;
    const InfFile::InfFileField *pRequiredFields;
};

static const InfFileInstall infFileInstallList[] = {
    { C0C_INF_NAME,          C0C_COPY_DRIVERS_SECTION,  C0C_BUS_DEVICE_ID,        TRUE,  requiredFieldsInfBusInstall },
    { C0C_INF_NAME_CNCPORT,  NULL,                      C0C_PORT_HW_ID_CNCCLASS,  FALSE, requiredFieldsInfCNCPortInstall },
    { C0C_INF_NAME_COMPORT,  NULL,                      C0C_PORT_HW_ID_COMCLASS,  FALSE, requiredFieldsInfCOMPortInstall },
    { NULL },
    };
///////////////////////////////////////////////////////////////
static const InfFile::InfFileField requiredFieldsInfUnnstallInfTag[] = {
    { "Version",         "UninstallInfTag",    1, C0C_CNCCLASS_GUID },
    { "Manufacturer",    NULL,                 1, C0C_SERVICE },
    { NULL },
    };

static const InfFile::InfFileField requiredFieldsInfUnnstallCNCOld[] = {
    { "Version",         "ClassGUID",          1, C0C_CNCCLASS_GUID },
    { "Version",         "Provider",           1, C0C_PROVIDER },
    { "Version",         "CatalogFile",        1, "com0com.cat" },
    { NULL },
    };

static const InfFile::InfFileField requiredFieldsInfUnnstallCNCClass[] = {
    { "Version",         "ClassGUID",          1, C0C_CNCCLASS_GUID },
    { NULL },
    };

static const InfFile::InfFileField requiredFieldsInfUnnstallCOMClass[] = {
    { "Version",         "ClassGUID",          1, C0C_COMCLASS_GUID },
    { "Manufacturer",    NULL,                 1, C0C_SERVICE },
    { NULL },
    };

static const InfFile::InfFileUninstall infFileUninstallList[] = {
    { requiredFieldsInfUnnstallInfTag,    FALSE },
    { requiredFieldsInfUnnstallCNCOld,    FALSE },
    { requiredFieldsInfUnnstallCNCClass,  TRUE },
    { requiredFieldsInfUnnstallCOMClass,  TRUE },
    { NULL },
    };

#endif // C_C_DEF_H
